/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package ms.jasim.model.items.impl;

import java.util.Collection;

import ms.jasim.framework.IJasimAppContext;
import ms.jasim.model.ModelObject;
import ms.jasim.model.ModelPackage;
import ms.jasim.model.NamedModelObject;
import ms.jasim.model.items.Item;
import ms.jasim.model.items.ItemList;
import ms.jasim.model.items.ItemsPackage;
import ms.utils.EObjectListImpl;
import ms.utils.INamedItem;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc --> An implementation of the model object '
 * <em><b>Item List</b></em>'. <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 * <li>{@link ms.jasim.model.items.impl.ItemListImpl#getItem <em>Item</em>}</li>
 * </ul>
 * </p>
 * 
 */
public class ItemListImpl extends EObjectListImpl<Item> implements ItemList {
	/**
	 * The default value of the '{@link #isPredefined() <em>Predefined</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isPredefined()
	 * @generated
	 * @ordered
	 */
	protected static final boolean PREDEFINED_EDEFAULT = false;
	/**
	 * The cached value of the '{@link #isPredefined() <em>Predefined</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isPredefined()
	 * @generated
	 * @ordered
	 */
	protected boolean predefined = PREDEFINED_EDEFAULT;
	/**
	 * The default value of the '{@link #isReadonly() <em>Readonly</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isReadonly()
	 * @generated
	 * @ordered
	 */
	protected static final boolean READONLY_EDEFAULT = false;
	/**
	 * The cached value of the '{@link #isReadonly() <em>Readonly</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isReadonly()
	 * @generated
	 * @ordered
	 */
	protected boolean readonly = READONLY_EDEFAULT;
	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;
	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;
	/**
	 * The default value of the '{@link #isReservedName() <em>Reserved Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isReservedName()
	 * @generated
	 * @ordered
	 */
	protected static final boolean RESERVED_NAME_EDEFAULT = false;
	/**
	 * The cached value of the '{@link #isReservedName() <em>Reserved Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isReservedName()
	 * @generated
	 * @ordered
	 */
	protected boolean reservedName = RESERVED_NAME_EDEFAULT;
	/**
	 * The cached value of the '{@link #getItem() <em>Item</em>}' containment reference list.
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * @see #getItem()
	 * @generated
	 * @ordered
	 */
	protected EList<Item> item;
	private String text;

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 */
	public ItemListImpl() {
		super();
		setInternalList(getItem());
	}

	public ItemListImpl(String string) {
		setName(string);
		setPredefined(true);
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return ItemsPackage.Literals.ITEM_LIST;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ItemsPackage.ITEM_LIST__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean isReservedName() {
		return reservedName;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void setReservedName(boolean newReservedName) {
		boolean oldReservedName = reservedName;
		reservedName = newReservedName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ItemsPackage.ITEM_LIST__RESERVED_NAME, oldReservedName, reservedName));
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Item> getItem() {
		if (item == null) {
			item = new EObjectContainmentEList<Item>(Item.class, this, ItemsPackage.ITEM_LIST__ITEM);
		}
		return item;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 */
	@Override
	public boolean isPredefined() {
		return super.isPredefined();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 */
	@Override
	public void setPredefined(boolean value) {
		super.setPredefined(value);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean isReadonly() {
		return readonly;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void setReadonly(boolean newReadonly) {
		boolean oldReadonly = readonly;
		readonly = newReadonly;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ItemsPackage.ITEM_LIST__READONLY, oldReadonly, readonly));
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd,
			int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ItemsPackage.ITEM_LIST__ITEM:
				return ((InternalEList<?>)getItem()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case ItemsPackage.ITEM_LIST__PREDEFINED:
				return isPredefined();
			case ItemsPackage.ITEM_LIST__READONLY:
				return isReadonly();
			case ItemsPackage.ITEM_LIST__NAME:
				return getName();
			case ItemsPackage.ITEM_LIST__RESERVED_NAME:
				return isReservedName();
			case ItemsPackage.ITEM_LIST__ITEM:
				return getItem();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case ItemsPackage.ITEM_LIST__PREDEFINED:
				setPredefined((Boolean)newValue);
				return;
			case ItemsPackage.ITEM_LIST__READONLY:
				setReadonly((Boolean)newValue);
				return;
			case ItemsPackage.ITEM_LIST__NAME:
				setName((String)newValue);
				return;
			case ItemsPackage.ITEM_LIST__RESERVED_NAME:
				setReservedName((Boolean)newValue);
				return;
			case ItemsPackage.ITEM_LIST__ITEM:
				getItem().clear();
				getItem().addAll((Collection<? extends Item>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case ItemsPackage.ITEM_LIST__PREDEFINED:
				setPredefined(PREDEFINED_EDEFAULT);
				return;
			case ItemsPackage.ITEM_LIST__READONLY:
				setReadonly(READONLY_EDEFAULT);
				return;
			case ItemsPackage.ITEM_LIST__NAME:
				setName(NAME_EDEFAULT);
				return;
			case ItemsPackage.ITEM_LIST__RESERVED_NAME:
				setReservedName(RESERVED_NAME_EDEFAULT);
				return;
			case ItemsPackage.ITEM_LIST__ITEM:
				getItem().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case ItemsPackage.ITEM_LIST__PREDEFINED:
				return predefined != PREDEFINED_EDEFAULT;
			case ItemsPackage.ITEM_LIST__READONLY:
				return readonly != READONLY_EDEFAULT;
			case ItemsPackage.ITEM_LIST__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case ItemsPackage.ITEM_LIST__RESERVED_NAME:
				return reservedName != RESERVED_NAME_EDEFAULT;
			case ItemsPackage.ITEM_LIST__ITEM:
				return item != null && !item.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public int eBaseStructuralFeatureID(int derivedFeatureID, Class<?> baseClass) {
		if (baseClass == ModelObject.class) {
			switch (derivedFeatureID) {
				case ItemsPackage.ITEM_LIST__PREDEFINED: return ModelPackage.MODEL_OBJECT__PREDEFINED;
				case ItemsPackage.ITEM_LIST__READONLY: return ModelPackage.MODEL_OBJECT__READONLY;
				default: return -1;
			}
		}
		if (baseClass == INamedItem.class) {
			switch (derivedFeatureID) {
				default: return -1;
			}
		}
		if (baseClass == NamedModelObject.class) {
			switch (derivedFeatureID) {
				case ItemsPackage.ITEM_LIST__NAME: return ModelPackage.NAMED_MODEL_OBJECT__NAME;
				case ItemsPackage.ITEM_LIST__RESERVED_NAME: return ModelPackage.NAMED_MODEL_OBJECT__RESERVED_NAME;
				default: return -1;
			}
		}
		if (baseClass == Item.class) {
			switch (derivedFeatureID) {
				default: return -1;
			}
		}
		return super.eBaseStructuralFeatureID(derivedFeatureID, baseClass);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public int eDerivedStructuralFeatureID(int baseFeatureID, Class<?> baseClass) {
		if (baseClass == ModelObject.class) {
			switch (baseFeatureID) {
				case ModelPackage.MODEL_OBJECT__PREDEFINED: return ItemsPackage.ITEM_LIST__PREDEFINED;
				case ModelPackage.MODEL_OBJECT__READONLY: return ItemsPackage.ITEM_LIST__READONLY;
				default: return -1;
			}
		}
		if (baseClass == INamedItem.class) {
			switch (baseFeatureID) {
				default: return -1;
			}
		}
		if (baseClass == NamedModelObject.class) {
			switch (baseFeatureID) {
				case ModelPackage.NAMED_MODEL_OBJECT__NAME: return ItemsPackage.ITEM_LIST__NAME;
				case ModelPackage.NAMED_MODEL_OBJECT__RESERVED_NAME: return ItemsPackage.ITEM_LIST__RESERVED_NAME;
				default: return -1;
			}
		}
		if (baseClass == Item.class) {
			switch (baseFeatureID) {
				default: return -1;
			}
		}
		return super.eDerivedStructuralFeatureID(baseFeatureID, baseClass);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (Predefined: ");
		result.append(predefined);
		result.append(", Readonly: ");
		result.append(readonly);
		result.append(", Name: ");
		result.append(name);
		result.append(", ReservedName: ");
		result.append(reservedName);
		result.append(')');
		return result.toString();
	}

	@Override
	public String getLabel() {
		String label = getText();
		return label == null || label.length() == 0 ? "[Name]" : label;
	}

	@Override
	public Object getValue(IJasimAppContext context) {
		return null;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 */
	@Override
	public boolean isTemplateObject() {
		return super.isTemplateObject();
	}

	@Override
	public void setValue(IJasimAppContext context, Object value) {
		// TODO Auto-generated method stub
		
	}

	
	@Override
	public String getText() {
		return text != null && text.length() > 0 ? text : getName();
	}

	
	@Override
	public void setText(String value) {
		String oldText = text;
		text = value;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ItemsPackage.ITEM__TEXT, oldText, text));
	}

	
} //ItemListImpl
